// TOWN SCRIPT
//    Town 4: Underground

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering
//Be afraid of the lame, they'll inherit your legs
//Be afraid of the old, they'll inherit your souls
//Be afraid of the cold, they'll inherit your blood
//Aprs moi le deluge, after me comes the flood

//intro
if(get_flag(4,0) == 0) {
	reset_dialog();
	add_dialog_str(0,"After a short climb you emerge into a small, musty-smelling chamber. Despite being underground the room is well lit - a torch hangs on the wall, still burning brightly, after all these years.",0);
	add_dialog_str(1,"As you step away from the ladder, you hear a crash from above, and what little light was filtering down from the temple disappears. It looks as though your route out has been blocked - there is no way but forward.",0);
	run_dialog(1);
	set_flag(4,1,1);
}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.

break;

//Ladder - no way out.
beginstate 10;
	message_dialog("You attempt to climb up the ladder, but somebody has placed something large and heavy over the exit - you won't be able to get out this way right now.","");
	block_entry(1);
break;

//Bone room
beginstate 11;
	if(get_flag(4,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"This room is grim indeed - upon entering you are assulted with the stale stench of death, and piles of bones litter the floor and counters.",0);
		add_dialog_str(1,"At first you think you have discovered the fate of the citizens of this island, but that can't be right - there are maybe a dozen skeletons here, which isn't nearly enough considering the size of the settlement above.",0);
		add_dialog_str(2,"Instead you realise that this must be some kind of burial chamber or crypt for wealthy or important people. You move further into the room, when suddenly, a huge blast of wind throws you back, and out of the door to the south, throwing it open.",0);
		add_dialog_str(3,"You stand back up and regain yourselves, hoping that you haven't just unleashed some kind of curse upon yourself.",0);
		run_dialog(1);
		set_flag(4,1,1);
		flip_terrain(13,14);
	}	
break;

//Angel appears behind them, approaching two-room cavern
beginstate 12;
	if(get_flag(4,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you're walking down this tunnel you hear a crashing sound from behind you. Jumping around, you see that the way back into the crypt is blocked by a huge, unmoving figure - an angel.",0);
		add_dialog_str(1,"It has its hands in front of its eyes, covering them for some reason. Unfortunately, you'll have to press on instead of going back - you're not sure what these angels are, but you certainly don't want to get any closer to them than you have to.",0);
		add_dialog_str(2,"Keeping your eyes on it, you slowly back off until it is out of sight.",0);
		run_dialog(1);
		set_terrain(13,15,441);
		set_flag(4,2,1);
	}
break;

//Stop them going any further
beginstate 13;
	if(get_flag(4,2) == 1) {
		message_dialog("The angel is still blocking the doorway back into the crypt, and to the temple. As much as you feel that you are being herded further into the cave, you have no choice but to turn around.","Even if you wanted to get any closer to the statue, which you don't, there is no way you'd be able to squeeze past it and out of the door. You turn around, and move on.");
		block_entry(1);
	}
break;

//Another angel
beginstate 14;
	if(get_flag(4,3) == 0) {
		reset_dialog();
		add_dialog_str(0,"Once again, as you're traveling further into the cave you hear a noise behind you. As you turn around you see another statue on the path behind you. However, there is something different about this one...",0);
		add_dialog_str(1,"All of the other angels you have seen have been shielding their eyes; this one is not. You stare into its lifeless eyes and feel dread. It is completely empty - it seems to be sucking in the warmth and light around it.",0);
		add_dialog_str(2,"You shudder, and let your gaze slip for a moment. Quickly, just a split-second later, you look back up at the statue - it's moved closer. A lot closer. It's as if they can only move when they aren't being observed.",0);
		add_dialog_str(3,"The warning you read earlier when entering the town above comes flying back to you: _DON'T BLINK_. Keeping your eyes fixed on the statue you back away, and around the corner, until you can no longer see it.",0);
		add_dialog_str(4,"Whatever they are pushing you towards, you have a feeling the angels mean you nothing but ill. Swallowing hard, you move on, more alert than before.",0);
		run_dialog(1);
		set_flag(4,3,1);
		set_terrain(25,33,441);
	}
break;


//stop them going further
beginstate 15;
	if(get_flag(4,3) == 1) {
		message_dialog("As you move back down this tunnel, you can't take your eyes off the angel in front of you. Where before they had always covered their faces, this one is staring right at you.","You make it a few steps further before you stop - you can't bear to get any closer to this strange, dead thing. You back away slowly, not taking your eyes off the statue until you're out of its sight.");
		block_entry(1);
	}
break;

//crossing large s cavern
beginstate 16;
	if(get_flag(4,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"You shake your head slightly to clear it - you're sure that you can hear something up ahead, but you can't quite make out what.",0);
		add_dialog_str(1,"Moving further into the cavern, you cock your head to one side and listen intently - you can just about make out a rasping syncopated sound ahead. If it's speaking, it's not in a language you understand.",0);
		add_dialog_str(2,"Perhaps, though, up ahead is a survivor - somebody who can tell you what happened to the people here. And what exactly those angel statues are.",0);
		run_dialog(1);
		set_flag(4,4,1);
	}
break;

//Stop chanting
beginstate 17;
	if(get_flag(4,5) == 0) {
		message_dialog("As suddenly as you heard the strange rasping sound start, it stops, and the caves fall silent again...","");
		set_flag(4,5,1);
	}
break;

//Northern chest
beginstate 18;
	if(get_flag(4,6) == 0) {
		message_dialog("This stone chest is empty, apart from a few broken tools and old lamp casings. Needless to say, none of it is of any use to you. You close the chest and move on.","");
		set_flag(4,6,1);
		block_entry(1);
	} else {
		message_dialog("You have already looked in here.","");
		block_entry(1);
	}
break;

//Southern Box
beginstate 19;
	if(get_flag(4,7) == 0) {
		reset_dialog();
		add_dialog_str(0,"This stone chest is mostly full of broken tools and other assorted rubbish. However, tucked away at the bottom, wrapped in a dirty old cloth, you find a small crystal.",0);
		add_dialog_str(1,"You lift it out, and look it over. It feels warm to the touch and vibrates slightly in your hand - it must be a shattering stone, a powerful device capable of smashing down unstable walls. Do you take it with you?",0);
		add_dialog_choice(0,"Yes, take the crystal.");
		add_dialog_choice(1,"No, leave it alone.");
		if(run_dialog(1) == 1) {
			message_dialog("You take the crystal, and close the chest behind you.","");
			reward_give(328);
			set_flag(4,7,1);
			end();
		} else {
			message_dialog("You put the crystal back - although it seems to be alright still, it has been locked away for a very long time - the last thing you need now is it exploding in your face when you try to use it.","You close the chest and move on.");
			end();
		}
	}
break;	

//Approaching crystal spire
beginstate 20;
	if(get_flag(4,8) == 0) {
		reset_dialog();
		add_dialog_str(0,"You climb this long, wide gallery, which gently slopes up to the south. At the far end of the cave you can see a bunch of crystal formations circling a much taller, more impressive crystal spire.",0);
		add_dialog_str(1,"As you draw closer to it the rasping sound you heard earlier returns, and you hear movement back in the caves you have just passed through - whatever the angel's reason for bringing you here, you suspect it involves this chamber.",0);
		add_dialog_str(2,"You ready your weapon and continue forward.",0);
		run_dialog(1);
		set_flag(4,8,1);
	}
break;

//TALKING
beginstate 21;
	if(get_flag(250,1) == 0) {
		begin_talk_mode(1); 
	} else {
		end();
	}
break;

//Crystal Spire
beginstate 22;
	reset_dialog();
	add_dialog_str(0,"You approach the large crystal spire - if it is alive, like the voice said earlier, it certainly doesn't show it. As you walk around it, inspecting it, you realise that one well-aimed blow with your weapon would be enough to shatter it.",0);
	add_dialog_str(1,"Of course, once you do, you'll have freed the angels from their imprisonment here... What do you wish to do?",0);
	add_dialog_choice(0,"Smash the crystal.");
	add_dialog_choice(1,"Leave it alone.");
	if(run_dialog(1) == 1) {
		message_dialog("You raise your weapon and strike the crystal as hard as you can. It shatters immediately, sending fragments of rock all over you.","Suddenly, everything goes dark...");
		move_to_new_town(5,36,38);
	} else {
		message_dialog("You decide not to smash the crystal - there's no knowing what will happen if you do.","");
		block_entry(1);
	}
break;	

//Stop them escaping
beginstate 23;
	if(get_flag(250,1) == 1) {
		message_dialog("The two angel statues to the north glare at you, blocking the path back to the surface of the island. You won't be able to pass them without taking your eyes off them, at which time...","You will have to smash the crystal and hope you are not double-crossed...");
		block_entry(1);
	}
break;

//sarco
beginstate 24;
	message_dialog("This sarcophagus is sealed shut. You try to budge the lid but it doesn't move an inch.","");
break;